package com.yjf.mydockerCompose.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * HelloController
 *
 * @author 帅气的杨大哥
 * @version 1.0
 * @date 2023/6/18 9:48
 */
@Slf4j
@RestController
@RequestMapping("/hello")
public class HelloController {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/hello")
    public String hello(){
        LocalDateTime currentDateTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = currentDateTime.format(formatter);
        return formattedDateTime;
    }

    @GetMapping("/postgres/version")
    public String getPostgreSQLVersion() {
        String sql = "SELECT version()";
        String version = jdbcTemplate.queryForObject(sql, String.class);
        return "PostgreSQL version: " + version;
    }
}
